import request from '@/utils/request';
import { SupVO, SupForm, SupQuery } from '@/api/system/supplier/types';
import { AxiosPromise } from 'axios';

/**
 * 供应商列表
 * @param query 
 * @returns 
 */
export const listSupplier = (query: SupQuery): AxiosPromise<TableInfoVO<SupVO>> => {
  return request({
    url: '/supplier/list',
    method: 'get',
    params: query
  });
};

/**
 * 添加供应商
 * @param data 
 * @returns 
 */
export const addSupplier = (data: SupForm) => {
  return request({
    url: '/supplier',
    method: 'post',
    data: data
  });
};

/**
 * 修改供应商
 * @param data 
 * @returns 
 */
export const updateSupplier = (data: SupForm) => {
  return request({
    url: '/supplier',
    method: 'put',
    data: data
  });
};

/**
 * 删除供应商
 * @param id 
 * @returns 
 */
export const delSupplier = (id: string | number) => {
  return request({
    // url: '/system/role/' + roleId,
    url: `/supplier/${id}`,
    method: 'delete'
  });
};

/**
 * 供应商启用禁用
 * @param id 
 * @returns 
 */
export const enableSupplier = (id: string | number) => {
  return request({
    url: `/supplier/enable/${id}`,
    method: 'put'
  });
};

/**
 * 查询已经启用的供应商，--商品添加修改时，选择供应商使用
 * @returns 
 */
export const listValidSupplier = (): AxiosPromise<SupVO[]> => {
  return request({
    url: '/supplier/list-valid',
    method: 'get',
  });
};